$allEvent=Get-EventLog -LogName Application | where {$_.TimeGenerated -gt (Get-Date).AddDays(-5)} 
$allEventCount=$allEvent | Measure-Object | Select-Object -ExpandProperty Count
# $allEventCount=$allEvent.Count # this also works


$allErrorEventCount=(Get-EventLog -LogName Application | where {($_.TimeGenerated -gt (Get-Date).AddDays(-5)) -and ($_.EntryType -eq "Error")}).Count
# $allErrorEventCount=($allEvent | where {$_.EntryType -eq "Error"}).count
$allErrorEventCount

$errorRate=($allErrorEventCount/$allEventCount)*100
$errorRateText="Error rate is gonna be {0:N5}" -f $errorRate
$errorRateText

foreach ($event in $allEvent)
{
    if($event.Message -match "软件保护")
    {
        $event.Message
    }
}
